﻿// Copyright Microsoft

using System;
using System.Windows;
using System.Activities.Presentation.View;
using System.Activities.Presentation;
using System.Activities.Presentation.Model;
using Microsoft.Samples.SqlServer.ExtensionMethods;
using System.Activities;
using System.Net;
using System.Linq;
using System.Activities.Statements;
using System.Collections.ObjectModel;
using System.Data.SqlClient;

namespace Microsoft.Samples.SqlServer.Activities.Designers
{
  // Interaction logic for ConnectionActivityDesigner.xaml
  public partial class ConnectionActivityDesigner
  {
    public ConnectionActivityDesigner()
    {
      InitializeComponent();
    }

    private void ActivityDesigner_Loaded(object sender, RoutedEventArgs e)
    {
        //NOTE: The sample assumes a Sequence ConnectionBuilder variable as SqlConnectionBuilder
        Sequence rootSequence = this.ModelItem.RootSequence() as Sequence;
        if (rootSequence != null)
        {
            this.ModelItem.Properties["NetworkCredential"].SetValue(new InArgument<ICredentials>(
            (from v in rootSequence.Variables
             where v.Name == "Credentials"
             select v).First()));

            //NOTE: The sample assumes a Sequence ConnectionBuilder variable as SqlConnectionBuilder
            this.ModelItem.Properties["SqlConnectionBuilder"].SetValue(new OutArgument<SqlConnectionStringBuilder>(
                (from v in rootSequence.Variables
                 where v.Name == "ConnectionStringBuilder"
                 select v).First()));
        }
    }
  }
}
